# -*- coding：utf-8 -*-
"""
@Time:2024-10-0721:12
@Auth:泛彼泊舟
@File:main_util.py
@IDE:PyCharm
@模块功能：xxx
"""
from common.function.assert_util import AssertUtil
from common.function.extract_util import ExtractUtil
from common.module.model_util import verify_yaml
from common.request.requests_util import RequestUtil

eu = ExtractUtil()
ru = RequestUtil()
au = AssertUtil()
def stand_case_flow(caseinfo):
    #  校验yaml数据
    case_obj = verify_yaml(caseinfo)
    # 使用提取的值，把${}替换成具体的值
    print(case_obj.request)
    new_request = eu.change(case_obj.request)
    # 发送请求
    res = ru.send_all_request(**new_request)
    # 请求之后得到响应提取变量
    if case_obj.extract:
        for key, value in case_obj.extract.items():
            eu.extract(res, key, *value)

    # 请求之后得到响应后，如果validate不为None,则需要断言
    if case_obj.validate:
        for assert_type,value in case_obj.validate.items():
            au.assert_all_case(res, assert_type, value)
    else:
        print("该用例不需要断言！")